import component from "../../../common/component";
import {Button, Col, Input,Row,Tag} from "antd";
import EditModal from "./edit";
import BorrowBtn from "@/components/BorrowBtn"
import ViewBtn from "@/components/ViewBtn";

class borrows extends component {

    //搜索栏  搜索栏不可指定搜索属性搜索
    getSearchRow(): null {
        return <Input.Group>
            <Row gutter={8}>
                <Col span={6}>
                    <Input onChange={this.handleChange} allowClear placeholder="设备名称" onPressEnter={this.reload}
                           name={'name'}/>
                </Col>
                <Col span={3}>
                    <Button type={'primary'} onClick={this.reload}>搜索</Button>
                </Col>
            </Row>
        </Input.Group>;
    }

    //主体部分页眉
    getColumns(): null {
        return [
            {
                title: '设备编号',
                dataIndex: 'equCode',
                key: 'equCode',
                width: 150,
              
            },
            {
                title: '设备名称',
                dataIndex: 'name',
                key: 'name',
                width: 150,
            },
             //传回类型id 前端解析
            {
                title: '设备类型',
                dataIndex: 'className',
                key: 'className',
                width: 150,
               
            },
            {
                title: '生产厂家',
                dataIndex: 'manufacturer',
                key: 'manufacturer',
                width: 150,
            },
            {
                title: '入库日期',
                dataIndex: 'date',
                key: 'date',
                width: 150,
                sorter: (a, b) => {
                    // 将日期转成毫秒
                      const t1 = new Date(a.date).getTime();
                      const t2 = new Date(b.date).getTime();
                      return t1- t2
                    },
                    sortDirections: ['descend', 'ascend'],
                    defaultSortOrder: 'descend'
              
            },
            {
                title: '设备地址',
                dataIndex: 'place',
                key: 'place',
                width: 150,
                
            },
            //int型 三元解析式
            {
                title: '设备状态',
                dataIndex: 'state',
                key: 'state',
                width: 100,
                render (state) { 
                    let config = {
                        '在库中': <Tag color='success'>在库中</Tag>,
                        '已借出': <Tag color="default">已借出</Tag>,
                        '维修中': <Tag color="processing">维修中</Tag>
                    }
                    return config[state];
                }
               
               
            },
            {
                title: '规格型号',
                dataIndex: 'specification',
                key: 'specification',
                width: 150,
             
            },
            {
                title: '技术参数',
                dataIndex: 'tparameter',
                key: 'tparameter',
                width: 150,
             
            },
            {
                title: '标定参数',
                dataIndex: 'cparameter',
                key: 'cparameter',
                width: 150,
               
            },
            {
                title: '设备图片',
                dataIndex: 'operation',
                width: 150,
                render: (_, record) => {
                    return <ViewBtn record={record} indexId='0'  baseUir={this.state.baseUri} />
                },
            },
            {
                title: '设备使用视频',
                dataIndex: 'operation',
                width: 150,
                render: (_, record) => {
                    return <ViewBtn record={record} indexId='1' baseUir={this.state.baseUri}/>
                },
            }, 
            {
                title: '设备使用文档',
                dataIndex: 'operation',
                width: 150,
                render: (_, record) => {
                    return <ViewBtn  record={record} indexId='2' baseUir={this.state.baseUri}/>
                },
               
            },
            {
                title: '备注',
                dataIndex: 'notes',
                key: 'notes',
                width: 100,
              
            },
            {
                title: '操作',
                dataIndex: 'operation',
                fixed: 'right',
                width: 100,
                render: (_, record) => {
                    return <BorrowBtn record={record} edit={this.edit}/>
                },
            }
        ];
    }


    getEditModal(): null {
        return <EditModal {...this.state.editParam} cancelModal={this.cancelModal} reload={this.reload}
                          baseUir={this.state.baseUri}/>
    }
}

export default borrows;
